//package com.ketangpai.admin.dao;
//
//import com.baomidou.mybatisplus.core.mapper.BaseMapper;
//import com.ketangpai.admin.entity.StuWork;
//import com.ketangpai.admin.entity.dto.StuWorkDTO;
//import com.ketangpai.admin.entity.param.StuWorkParam;
//import org.apache.ibatis.annotations.*;
//
//import java.util.List;
//
//@Mapper
//public interface StuWorkDao extends BaseMapper<StuWork> {
//@Select("SELECT COUNT(*) FROM stu_work WHERE work_id = #{work_id} AND status = #{status}")
//    Integer countStatus(Integer work_id, Integer status);
//
//    //根据用户、课程id查询作业
//    @Select("SELECT * FROM stu_work WHERE work_id = #{id} and user_id=#{userId} ")
//    StuWorkDTO queryById(Integer id,Integer userId);
//
//    //根据条件分页查询作业
//    List<StuWorkDTO> queryAllByLimit(@Param("param") StuWorkParam param);
//
//    Integer getTotal(@Param("param") StuWorkParam param);//根据条件查询总数
//
//    Integer getAllTotal(@Param("param") StuWorkParam param);//根据作业id查询总数
//    @Delete("DELETE FROM stu_work WHERE course_id=#{courseId}")
//    boolean deleteByCourseId(Integer courseId);
//    @Delete("DELETE FROM stu_work WHERE work_id=#{workId} and user_id=#{userId}")
//    boolean deleteByWidUid(Integer workId,Integer userId);
//
//    @Insert("INSERT INTO stu_work (work_id, user_id, username) VALUES (#{workId}, #{userId}, #{userName})")
//    void createNew(Integer workId,Integer userId,String userName);
//}
package com.ketangpai.admin.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ketangpai.admin.entity.StuWork;
import com.ketangpai.admin.entity.dto.StuWorkDTO;
import com.ketangpai.admin.entity.param.StuWorkParam;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StuWorkDao extends BaseMapper<StuWork> {
    @Select("SELECT COUNT(*) FROM stu_work WHERE work_id = #{work_id} AND status = #{status}")
    Integer countStatus(Integer work_id, Integer status);

    //根据用户、课程id查询作业
    @Select("SELECT * FROM stu_work WHERE work_id = #{id} and user_id=#{userId} ")
    StuWorkDTO queryById(Integer id,Integer userId);

    //根据条件分页查询作业
    List<StuWorkDTO> queryAllByLimit(@Param("param") StuWorkParam param);

    Integer getTotal(@Param("param") StuWorkParam param);//根据条件查询总数

    Integer getAllTotal(@Param("param") StuWorkParam param);//根据作业id查询总数
    @Delete("DELETE FROM stu_work WHERE course_id=#{courseId}")
    boolean deleteByCourseId(Integer courseId);

    @Select("SELECT user_id FROM user_course WHERE course_id = #{courseId}")
    List<Integer> getStudentsByCourseId(@Param("courseId") Integer courseId);

    @Insert("INSERT INTO stu_work (work_id, user_id, status) VALUES (#{workId}, #{userId}, #{status})")
    int insert(StuWork stuWork);
    @Delete("DELETE FROM stu_work WHERE work_id=#{workId} and user_id=#{userId}")
    boolean deleteByWidUid(Integer workId,Integer userId);
    @Insert("INSERT INTO stu_work (work_id, user_id, username,content) VALUES (#{workId}, #{userId}, #{userName},#{content})")
    void createNew(Integer workId,Integer userId,String userName,String content);
}
